package com.motorwaymanage.actions;

import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.motorwaymanage.beans.Admin;
import com.motorwaymanage.beans.MaintainerInfo;
import com.motorwaymanage.biz.IAdminBiz;
import com.motorwaymanage.biz.IMaintainerInfoBiz;
import com.motorwaymanage.impl.AdminBizImpl;
import com.motorwaymanage.impl.MaintainerInfoBizImpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{
	
	private static final long serialVersionUID = 1L;
	
	private String account;
	private String pwd;
	private IAdminBiz adminBiz=new AdminBizImpl();
	private IMaintainerInfoBiz maintainerInfoBiz=new MaintainerInfoBizImpl();
	private int result;
	private HttpSession session;
	{
		session=ServletActionContext.getRequest().getSession();
	}
	
	public String login_admin(){
		Admin admin=adminBiz.checkAdmin(new Admin(1,"123"));
		if(admin!=null){
			session.setAttribute("adminInfo", admin);
			result=1;
		}else{
			result=0;
		}
		return SUCCESS;
	}
	
	public String login_staff(){
		MaintainerInfo mi=new MaintainerInfo();
		mi.setMid(Integer.valueOf(account));
		mi.setMpwd(pwd);
		MaintainerInfo maintainerInfo=maintainerInfoBiz.checkMaintainerLogin(mi);
		if(maintainerInfo!=null){
			session.setAttribute("staffInfo", maintainerInfo);
			result=1;
		}else{
			result=0;
		}
		return SUCCESS;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public int getResult() {
		return result;
	}
}
